package Thread;

import com.sun.javaws.jnl.PackageDesc;

import java.sql.Time;

public class ThreadDemo8 {

    public static void main(String[] args) throws InterruptedException {
//        serial();
        concurrency();
    }
    
    public static void serial() {
        long a = 0;
        long b = 0;
        long start = System.currentTimeMillis();
        for (long i = 0; i < 100_0000_0000L; i++) {
            a++;
        }
        for (long i = 0; i < 100_0000_0000L; i++) {
            b++;
        }
        long end = System.currentTimeMillis();
        System.out.println("串行执行的时间:"+ (end-start)+"ms");
    }

    public static void concurrency() throws InterruptedException {
        Thread t1 = new Thread(()->{
            long a = 0;
            for (long i = 0; i < 100_0000_0000L; i++) {
                a++;
            }
        });
        Thread t2 = new Thread(()->{
            long b = 0;
            for (long i = 0; i < 100_0000_0000L; i++) {
                b++;
            }
        });
        long start = System.currentTimeMillis();
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        long end = System.currentTimeMillis();
        System.out.println("并行执行的时间:"+ (end-start)+"ms");
    }

}
